/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package EDT.actions;

import EDT.form.PromoNivGradForm;
import EDT.obj.Calendrier;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author ali
 */
public class PromoGradNiv extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    
    
    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        PromoNivGradForm f = (PromoNivGradForm) form;
        
        //Calendrier c = new Calendrier();
        //Appel à l'API
        
        int annee = EDT.api.API.getAnnee(Integer.parseInt(f.getPromotion()));
        Calendrier c = EDT.api.API.getCalendrierPromo(Integer.parseInt(f.getPromotion()), f.getPeriode(),f.getNbrperiode(),f.getGroupe());
        c.setTitre("Emplois du temps " +" "+f.getFormation()+"<br/>Promotion : "+annee+"/"+(annee+1)+"<br/>Groupe : "+f.getGroupe());
        
        
        //c.setGuidePeriode(EDT.api.BDUser.getGuidePeriode(Integer.parseInt(f.getPromotion())));
        
        
      /*  
            Date d = new Date();
            Calendar cal = Calendar.getInstance(); 
            cal.setTime(d);
        
            cal.add(Calendar.DATE, -4);
           
            //cal.add(Calendar.DATE, 1);
        
            c.addCreneau(new Creneau("L3 INFO", "li345", "T001", "PPP", cal.getTime(), 800, 1100,"CM"));
            c.addCreneau(new Creneau("L3 INFO", "li345", "T001", "PPP", cal.getTime(), 1100, 1200,"TD"));
            c.addCreneau(new Creneau("L3 INFO", "li345", "T001", "PPP", cal.getTime(), 1700, 1800,"TD"));
        
            cal.add(Calendar.DATE, 1);
        
            c.addCreneau(new Creneau("L3 INFO", "li314", "T001", "X.YY", cal.getTime(), "8:00", "9:45","CM"));
            c.addCreneau(new Creneau("L3 INFO", "li314", "T001", "X.YY", cal.getTime(), "10:00", "11:45","TD"));
            c.addCreneau(new Creneau("L3 INFO", "li314", "T001", "X.YY", cal.getTime(), "15:00", "16:45","CM"));
        
            cal.add(Calendar.DATE, 1);
        
            c.addCreneau(new Creneau("L3 INFO", "li310", "T001", "PPP", cal.getTime(), "8:00", "11:00","CM"));
            c.addCreneau(new Creneau("L3 INFO", "li310", "T001", "PPP", cal.getTime(), "11:00", "12:00","TD"));
            c.addCreneau(new Creneau("L3 INFO", "li310", "T001", "PPP", cal.getTime(), "17:00", "18:00","CM"));
        
            cal.add(Calendar.DATE, 1);
        
            c.addCreneau(new Creneau("L3 INFO", "li311", "T001", "PPP", cal.getTime(), "8:00", "11:00","CM"));
            c.addCreneau(new Creneau("L3 INFO", "li311", "T001", "PPP", cal.getTime(), "11:00", "12:00","TD"));
            c.addCreneau(new Creneau("L3 INFO", "li311", "T001", "PPP", cal.getTime(), "17:00", "18:00","CM"));
        
            cal.add(Calendar.DATE, 6);
        
            c.addCreneau(new Creneau("L3 INFO", "li311", "T001", "PPP", cal.getTime(), "8:00", "11:00","TD"));
            c.addCreneau(new Creneau("L3 INFO", "li316", "T001", "PPP", cal.getTime(), "11:00", "12:00","TD"));
            c.addCreneau(new Creneau("L3 INFO", "li311", "T001", "PPP", cal.getTime(), "17:00", "18:00","TD"));
        
        
        
            cal.add(Calendar.DATE, 13);
        
        c.addCreneau(new Creneau("L3 INFO", "li350", "T001", "PPP", cal.getTime(), "8:00", "11:00","TD"));
        c.addCreneau(new Creneau("L3 INFO", "li350", "T001", "PPP", cal.getTime(), "11:00", "12:00","TD"));
        c.addCreneau(new Creneau("L3 INFO", "li351", "T001", "PPP", cal.getTime(), "17:00", "18:00","TD"));
        //c.addJourFerier();
        
        */
        request.setAttribute("calendrier", c.perideToTableHTML());
        
        //return mapping.findForward(SUCCESS);
        //return mapping.findForward("calendrier");
        return mapping.findForward("calendrier");
        
    }
}
